package com.libweb.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.libweb.model.dao.BookDao;
import com.libweb.model.dao.RentDao;
import com.libweb.model.dto.Book;
import com.libweb.model.dto.Rent;

@WebServlet("/rent/reverseagree.action")
public class ReverseAgreeServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		//1. 객체를 만들고 사용자가 입력한 데이터를 저장
		Rent rent = new Rent();
		rent.setRentNo(Integer.parseInt(req.getParameter("rentno")));
		
		Book book = new Book();
		book.setBookNo(Integer.parseInt(req.getParameter("bookno")));

		//2. 데이터베이스에 변경된 내용 적용
		RentDao dao2 = new RentDao();
		dao2.reverseAgree(rent.getRentNo());
		
		BookDao dao = new BookDao();
		dao.reverseBook(book.getBookNo());	
		
		//3. 목록 페이지로 이동
		resp.sendRedirect("/libweb/rent/list.action?memberid=admin");	
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}






